Skip to content

feat: add external_id and metadata to organization resource#7

Closed
danielloader wants to merge 4 commits into
osodevops:mainfrom
danielloader:feat/organization-external-id-metadata
Closed

feat: add external_id and metadata to organization resource#7
danielloader wants to merge 4 commits into
osodevops:mainfrom
danielloader:feat/organization-external-id-metadata

Conversation

@danielloader

@danielloader danielloader commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add optional external_id (string) and metadata (map of string) attributes to the workos_organization resource
  • Update client models, CRUD handlers, and schema to support the new fields
  • Add acceptance test coverage for create, import, and update with the new attributes

Test plan

  • go build ./... passes
  • go vet ./... passes
  • go test ./internal/provider/ -run TestAccOrganizationResource_WithMetadataAndExternalID -v passes with WORKOS_API_KEY set
  • Existing acceptance tests still pass

🤖 Generated with Claude Code

Support optional external_id (string) and metadata (map of string)
fields on the workos_organization resource, matching the WorkOS API
Create/Update Organization endpoints.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@danielloader

Copy link
Copy Markdown
Contributor Author

Had to attempt a fix on the updated_at again as the test suite failed for me using a WORKOS_API_KEY for the full test suite:

TF_ACC=1 go test ./internal/provider/ -v
=== RUN   TestAccOrganizationRoleDataSource_BySlug
--- PASS: TestAccOrganizationRoleDataSource_BySlug (2.49s)
=== RUN   TestAccOrganizationRoleDataSource_ByID
--- PASS: TestAccOrganizationRoleDataSource_ByID (2.29s)
=== RUN   TestAccOrganizationDataSource_ByID
--- PASS: TestAccOrganizationDataSource_ByID (1.66s)
=== RUN   TestAccOrganizationDataSource_ByDomain
--- PASS: TestAccOrganizationDataSource_ByDomain (1.89s)
=== RUN   TestAccUserDataSource_ByID
--- PASS: TestAccUserDataSource_ByID (1.85s)
=== RUN   TestAccUserDataSource_ByEmail
--- PASS: TestAccUserDataSource_ByEmail (1.61s)
=== RUN   TestAccOrganizationMembershipResource_basic
--- PASS: TestAccOrganizationMembershipResource_basic (2.33s)
=== RUN   TestAccOrganizationMembershipResource_withRole
--- PASS: TestAccOrganizationMembershipResource_withRole (2.03s)
=== RUN   TestAccOrganizationRoleResource_Basic
    resource_organization_role_test.go:19: Step 3/3 error: Error running apply: exit status 1
        
        Error: Provider produced inconsistent result after apply
        
        When applying changes to workos_organization_role.test, provider
        "provider[\"registry.terraform.io/hashicorp/workos\"]" produced an unexpected
        new value: .updated_at: was cty.StringVal("2026-03-09T22:13:07Z"), but now
        cty.StringVal("2026-03-09T22:13:09Z").
        
        This is a bug in the provider, which should be reported in the provider's own
        issue tracker.
--- FAIL: TestAccOrganizationRoleResource_Basic (3.24s)
=== RUN   TestAccOrganizationRoleResource_NoDescription
--- PASS: TestAccOrganizationRoleResource_NoDescription (1.82s)
=== RUN   TestAccOrganizationResource_Basic
--- PASS: TestAccOrganizationResource_Basic (2.40s)
=== RUN   TestAccOrganizationResource_WithDomains
--- PASS: TestAccOrganizationResource_WithDomains (1.45s)
=== RUN   TestAccOrganizationResource_WithMetadataAndExternalID
--- PASS: TestAccOrganizationResource_WithMetadataAndExternalID (2.37s)
=== RUN   TestAccUserResource_basic
    resource_user_test.go:18: Step 3/3 error: Error running apply: exit status 1
        
        Error: Provider produced inconsistent result after apply
        
        When applying changes to workos_user.test, provider
        "provider[\"registry.terraform.io/hashicorp/workos\"]" produced an unexpected
        new value: .email_verified: was cty.True, but now cty.False.
        
        This is a bug in the provider, which should be reported in the provider's own
        issue tracker.
        
        Error: Provider produced inconsistent result after apply
        
        When applying changes to workos_user.test, provider
        "provider[\"registry.terraform.io/hashicorp/workos\"]" produced an unexpected
        new value: .updated_at: was cty.StringVal("2026-03-09T22:13:18Z"), but now
        cty.StringVal("2026-03-09T22:13:19Z").
        
        This is a bug in the provider, which should be reported in the provider's own
        issue tracker.
--- FAIL: TestAccUserResource_basic (2.02s)
=== RUN   TestAccUserResource_withPassword
--- PASS: TestAccUserResource_withPassword (1.31s)
=== RUN   TestAccUserResource_minimal
--- PASS: TestAccUserResource_minimal (1.09s)
FAIL
FAIL    github.com/osodevops/terraform-provider-workos/internal/provider        32.338s
FAIL

danielloader and others added 2 commits March 9, 2026 22:18
Replace UseStateForUnknown on updated_at across all four resources with
a custom plan modifier that preserves the state value when no config
attributes changed, but marks it unknown when they have. This prevents
both no-op plan drift and "inconsistent result after apply" errors on
real updates.

Also fix user resource to always send email_verified in update requests,
preventing the API from resetting it to false when the email changes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extend the workos_organization data source to support lookup by
external_id (via GET /organizations/external_id/:id), alongside the
existing id and domain lookup keys. Also exposes external_id and
metadata as computed outputs on the data source.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@danielloader

Copy link
Copy Markdown
Contributor Author

Additional: external_id lookup on organization data source

This latest commit extends the workos_organization data source to support lookup by external_id, complementing the existing id and domain lookup keys. It also exposes external_id and metadata as computed outputs on the data source.

Why this is on this PR rather than a separate branch

Since this PR already introduces external_id and metadata on the organization resource (and the underlying client structs), the data source changes depend directly on that work — the Organization struct fields, the client patterns, and the null-if-empty mapping conventions are all established here. Branching off this branch would create a stacked PR that can't merge independently and adds review overhead for what is a small, self-contained addition (one new client method, schema/model/read changes, and an acceptance test). Keeping it together means the feature ships complete: users get external_id and metadata on both the resource and the data source in a single release.

Changes

  • Client: Added GetOrganizationByExternalID — calls GET /organizations/external_id/:external_id
  • Data source schema: Added external_id (Optional+Computed) and metadata (Computed, map(string))
  • Data source validator: Extended ExactlyOneOf to include external_id
  • Data source Read: Added external ID lookup branch; maps external_id and metadata from response
  • Tests: Added TestAccOrganizationDataSource_ByExternalID acceptance test
  • Docs: Regenerated with go generate

… metadata

Add external_id and metadata to organization resource and data source examples.
Add external_id lookup example to organization data source.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
sionsmith added a commit that referenced this pull request Mar 12, 2026
…-metadata

feat: add external_id and metadata to organization resource
@sionsmith

Copy link
Copy Markdown
Contributor

Merged manually after rebasing onto main to resolve conflicts with #10 (domain uniqueness validation). All commits included, build and tests pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants